package com.wzdigit.wms.wms.service.core.trsn;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wzdigit.wms.basic.domain.order.TrsnHeader;
import com.wzdigit.wms.basic.mapper.core.order.TrsnHeaderMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 库存交易凭证表头，TRSN=Transaction Note，用于记录系统生成的入库、出库凭证 服务类
 * </p>
 *
 * @author
 * @since 2021-01-19
 */
@Service
@Slf4j
public class TrsnHeaderService {

    @Autowired
    TrsnHeaderMapper trsnHeaderMapper;

    /**
     * 根据入参实体新增一条记录
     * @param trsnHeader
     * @return
     */
    public TrsnHeader addNewOne(TrsnHeader trsnHeader) {
        int row = trsnHeaderMapper.insert(trsnHeader);
        log.info("成功新增{}条记录",row);

        return trsnHeader;
    }

    /**
     * 根据入参实体更新一条记录
     * @param trsnHeader
     * @return
     */
    public TrsnHeader updateOne(TrsnHeader trsnHeader) {
        int row = trsnHeaderMapper.updateById(trsnHeader);
        log.info("成功更新{}条记录",row);

        return trsnHeader;
    }

    public TrsnHeader selectByFmDoc(String gdnNo) {

        //创建类型的条件构造器
        QueryWrapper<TrsnHeader> wrapper = new QueryWrapper<>();
        wrapper.eq("FM_DOC", gdnNo);

        TrsnHeader trsnHeader = trsnHeaderMapper.selectOne(wrapper);
        return trsnHeader;
    }

    public TrsnHeader selectByFmDocAndNoteNo(String gdnNo, String trsnNoteNo) {

        //创建类型的条件构造器
        QueryWrapper<TrsnHeader> wrapper = new QueryWrapper<>();
        wrapper.eq("FM_DOC", gdnNo);
        wrapper.eq("NOTE_NO", trsnNoteNo);

        TrsnHeader trsnHeader = trsnHeaderMapper.selectOne(wrapper);
        return trsnHeader;
    }
}
